Reading and writing in memory

Contents|Index|Previous|Next
Reading and writing in memory

The classes, istrstream, ostrstream, and strstream, provide some additional features for reading and writing strings in memory—both static strings, and dynamically allocated strings. The underlying class, strstreambase, provides some features common to all three; strstreambuf underlies that in turn.

istrstream::istrstream (const char* str [, int size])
Constructor

Associate the new input string class, istrstream, with an existing static string, starting at str, of size, size. If you do not specify size, the string is treated as a NUL terminated string.

ostrstream::ostrstream ()
Constructor

Create a new stream for output to a dynamically managed string, which will grow as needed

ostrstream::ostrstream (char* str, int size [,int mode])
Constructor

A new stream for output to a statically defined string of length, size, starting at str. You may optionally specify one of the modes described for ifstream::ifstream; if you do not specify one, the new stream is simply open for output, with mode ios::out.

int ostrstream::pcount ()
Method

Report the current length of the string associated with this ostrstream.

char* ostrstream::str ()
Method

A pointer to the string managed by this ostrstream. Implies ostrstream::freeze().

Note:
If you want the string to be NUL terminated, you must do that yourself (perhaps by writing ends to the stream).

void ostrstream::freeze ([int n])
Method

If n is nonzero (the default), declare that the string associated with this ostrstream is not to change dynamically; while frozen, it will not be reallocated if it needs more space, and it will not be de-allocated when the ostrstream is destroyed. Use freeze(1) if you refer to the string as a pointer after creating it via ostrstream facilities. freeze(0) cancels this declaration, allowing a dynamically allocated string to be freed when its ostrstream is destroyed. If this ostrstream is already static—that is, if it was created to manage an existing statically allocated string—freeze is unnecessary, and has no effect.

int ostrstream::frozen ()
Method

Test whether freeze(1) is in effect for this string.

strstreambuf* strstreambase::rdbuf ()
Method

A pointer to the underlying strstreambuf.

Top|Contents|Index|Previous|Next